#ifndef CSDLGRAPHICS_H_
#define CSDLGRAPHICS_H_

#include "../bengine/CGraphics.h"
#include "CSDLFontEngine.h"
#include <SDL/SDL_ttf.h>
#include "CSDLColor.h"
#include "../platfinc.h"

namespace FBShells {
	class CSDLGraphics : public CGraphics {
		protected:
			Uint16 width, height;
		public:
			CSDLGraphics() { }
			virtual bool Initialize(unsigned int w, unsigned int h, bool fullscreen) {
				//initialize systems
				SDL_Init(SDL_INIT_VIDEO);
				width = w; height = h;
				CreateScreen();
				m_fontEngine = new CSDLFontEngine(this);
			}
			
			virtual bool Shutdown() {
				delete m_fontEngine;
			}
			
			virtual void CreateScreen() {
				SDL_SetVideoMode(width,height,0,SDL_ANYFORMAT);
			}
			
			SDL_Surface* GetScreen() {
				return SDL_GetVideoSurface();
			}
	
			// Draws a primitive circle to the screen. Unga bunga!
			virtual bool drawCircle(int x, int y, int radius, const CColor& color, bool fill) {
				if(fill)
					return filledEllipseRGBA(GetScreen(),x,y,radius,radius,color.getRed(),color.getGreen(),color.getBlue(),color.getAlpha()) < 0 ? false : true;
				else
					return ellipseRGBA(GetScreen(),x,y,radius,radius,color.getRed(),color.getGreen(),color.getBlue(),color.getAlpha()) < 0 ? false : true;
			}
			
			// Draws a primitive rectangle to the screen.
			virtual bool drawRect(int x, int y, int x2, int y2, const CColor& color, bool fill) {
				if(fill)
					return boxRGBA(GetScreen(),x,y,x2,y2,color.getRed(),color.getGreen(),color.getBlue(),color.getAlpha()) < 0 ? false : true;
				else
					return rectangleRGBA(GetScreen(),x,y,x2,y2,color.getRed(),color.getGreen(),color.getBlue(),color.getAlpha()) < 0 ? false : true;
			}

			// Draws a primitive triangle to the screen.
			virtual bool drawTriangle(int x, int y, int x2, int y2, int x3, int y3, const CColor& color, bool fill) {
				if(fill)
					return filledTrigonRGBA(GetScreen(),x,y,x2,y2,x3,y3,color.getRed(),color.getGreen(),color.getBlue(),color.getAlpha()) < 0 ? false : true;
				else
					return trigonRGBA(GetScreen(),x,y,x2,y2,x3,y3,color.getRed(),color.getGreen(),color.getBlue(),color.getAlpha()) < 0 ? false : true;
			}

			// Draws a primitive line to the screen.
			virtual bool drawLine(int x, int y, int x2, int y2, const CColor& color) {
				return lineRGBA(GetScreen(),x,y,x2,y2,color.getRed(),color.getGreen(),color.getBlue(),color.getAlpha()) < 0 ? false : true;
			}

			// Draws a pixel on the screen.
			virtual bool drawPixel(int x, int y, const CColor& color) {
				return pixelRGBA(GetScreen(),x,y,color.getRed(),color.getGreen(),color.getBlue(),color.getAlpha()) < 0 ? false : true;
			}
			
			// Draws a sprite to the screen.
			virtual bool drawSprite(CSprite* sprite) {
				
			}
			
			// // Draws a primitive sprite to the screen.
			// virtual bool drawCaveman(CSprite* caveman) = 0;
			
			// Draws a string to the screen. Overloaded for both std::string and char*.
			virtual bool drawString(int x, int y, std::string text, const CColor& facecolor, const CColor& background) {
				m_fontEngine->drawString(text,x,y);
			}
			
			virtual bool drawString(int x, int y, const char* text, const CColor& facecolor, const CColor& background) {
			
			}

			virtual CSprite* createSprite(std::string filename) { }
			virtual CSprite* createSprite(const char* filename) { }

			virtual void renderScreen() { 
			    SDL_Flip(GetScreen());
			    SDL_Delay(10);
			}
			
			virtual ~CSDLGraphics() { }
	};
};
	
#endif /*CSDLGRAPHICS_H_*/

